\hypertarget{class_r_t_o_s_1_1mailbox}{\section{R\-T\-O\-S\-:\-:mailbox$<$ T $>$ Class Template Reference}
\label{class_r_t_o_s_1_1mailbox}\index{R\-T\-O\-S\-::mailbox$<$ T $>$@{R\-T\-O\-S\-::mailbox$<$ T $>$}}
}


synchronous handling over of a data item  




{\ttfamily \#include $<$p\-R\-T\-O\-S.\-h$>$}

Inheritance diagram for R\-T\-O\-S\-:\-:mailbox$<$ T $>$\-:\begin{figure}[H]
\begin{center}
\leavevmode
\includegraphics[height=2.000000cm]{class_r_t_o_s_1_1mailbox}
\end{center}
\end{figure}
\subsection*{Public Member Functions}
\begin{DoxyCompactItemize}
\item 
\hyperlink{class_r_t_o_s_1_1mailbox_aaee470ef9fc6627e848e45ca353415ff}{mailbox} (const char $\ast$name=\char`\"{}\char`\"{})
\begin{DoxyCompactList}\small\item\em construtor, specify mutex name \end{DoxyCompactList}\item 
void \hyperlink{class_r_t_o_s_1_1mailbox_ad140965320e8b42ca16a5d288858f70d}{write} (const T item)
\begin{DoxyCompactList}\small\item\em write an item into the mailbox \end{DoxyCompactList}\item 
T \hyperlink{class_r_t_o_s_1_1mailbox_af2bc862b64929b5ec34afa4dec0ed720}{read} (void)
\begin{DoxyCompactList}\small\item\em read a value from the mailbox \end{DoxyCompactList}\end{DoxyCompactItemize}
\subsection*{Additional Inherited Members}


\subsection{Detailed Description}
\subsubsection*{template$<$class T$>$class R\-T\-O\-S\-::mailbox$<$ T $>$}

synchronous handling over of a data item 

\begin{DoxyVerb}  A mailbox is a template class synchronization mechanism. 
  A single value can be written to the mailbox. 
  Another task can read the value from the mailbox. 
  The read and write calls each wait on each other before they 
  are allowed to proceed.
  A mailbox is not created for a particular task, 
  and it is not a waitable.

  Initially a mailbox is empty. 
  The \ref write() operation bloks the calling task until 
  the mailbox is empty, then writes to the mailbox, and blocks. 
  The \ref read() operation blocks the calling task until 
  there is a value in the mailbox. 
  Then it reads the value, unblocks the task that wrote to 
  the mailbox, and returns. 

  The example below uses a mailbox to buffer writing cout 
  data to the UART. The function that writes each cout character 
  writes it to a mailbox, which is read by the  UART task. 
  This task waits 2 MS after each write to the UART, 
  to avoid busy waiting.

  @code 
\end{DoxyVerb}
 T\-B\-W  

\subsection{Constructor \& Destructor Documentation}
\hypertarget{class_r_t_o_s_1_1mailbox_aaee470ef9fc6627e848e45ca353415ff}{\index{R\-T\-O\-S\-::mailbox@{R\-T\-O\-S\-::mailbox}!mailbox@{mailbox}}
\index{mailbox@{mailbox}!RTOS::mailbox@{R\-T\-O\-S\-::mailbox}}
\subsubsection[{mailbox}]{\setlength{\rightskip}{0pt plus 5cm}template$<$class T$>$ {\bf R\-T\-O\-S\-::mailbox}$<$ T $>$\-::{\bf mailbox} (
\begin{DoxyParamCaption}
\item[{const char $\ast$}]{name = {\ttfamily \char`\"{}\char`\"{}}}
\end{DoxyParamCaption}
)\hspace{0.3cm}{\ttfamily [inline]}}}\label{class_r_t_o_s_1_1mailbox_aaee470ef9fc6627e848e45ca353415ff}


construtor, specify mutex name 

Create a mutex. The mutex is initially set. The template argument T must be a class that has a non-\/arguments constructor and supports assignment. 

\subsection{Member Function Documentation}
\hypertarget{class_r_t_o_s_1_1mailbox_af2bc862b64929b5ec34afa4dec0ed720}{\index{R\-T\-O\-S\-::mailbox@{R\-T\-O\-S\-::mailbox}!read@{read}}
\index{read@{read}!RTOS::mailbox@{R\-T\-O\-S\-::mailbox}}
\subsubsection[{read}]{\setlength{\rightskip}{0pt plus 5cm}template$<$class T$>$ T {\bf R\-T\-O\-S\-::mailbox}$<$ T $>$\-::read (
\begin{DoxyParamCaption}
\item[{void}]{}
\end{DoxyParamCaption}
)\hspace{0.3cm}{\ttfamily [inline]}}}\label{class_r_t_o_s_1_1mailbox_af2bc862b64929b5ec34afa4dec0ed720}


read a value from the mailbox 

If one or more tasks are waiting for the mutex the first one is released, and it now owns the mutex. Otherwise, if the mutex is cleared it is now set.

It is an error for a task to call signal() on a mutex that it does not own (that it did not call wait() on). After the signal the task no longer owns the mutex. \hypertarget{class_r_t_o_s_1_1mailbox_ad140965320e8b42ca16a5d288858f70d}{\index{R\-T\-O\-S\-::mailbox@{R\-T\-O\-S\-::mailbox}!write@{write}}
\index{write@{write}!RTOS::mailbox@{R\-T\-O\-S\-::mailbox}}
\subsubsection[{write}]{\setlength{\rightskip}{0pt plus 5cm}template$<$class T$>$ void {\bf R\-T\-O\-S\-::mailbox}$<$ T $>$\-::write (
\begin{DoxyParamCaption}
\item[{const T}]{item}
\end{DoxyParamCaption}
)\hspace{0.3cm}{\ttfamily [inline]}}}\label{class_r_t_o_s_1_1mailbox_ad140965320e8b42ca16a5d288858f70d}


write an item into the mailbox 

If the mutex was set it it is now cleared, and the calling task owns the mutex.

Otherwise the current task waits (is halted) until the owning task calls signal() on the same mutex. The signal() calls will release the tasks in the order of their wait() calls. 

The documentation for this class was generated from the following file\-:\begin{DoxyCompactItemize}
\item 
p\-R\-T\-O\-S.\-h\end{DoxyCompactItemize}
